<%@page import="cn.lily.com.enviroment.Enviroment"%>
<%@ page contentType="text/html; charset=utf-8" %>
<%@ page import="cn.lily.inst.web.frames.FrameConfig" %>
<%@ page import="cn.lily.web.util.context.WebContext" %>
<%@ page import="cn.lily.esb.context.AuthEntity" %>
<%@page import="cn.lily.com.db.sql.DBManager"%>
<%@page import="app.portal.dao.Pt_app_infoBean"%>
<%@page import="app.portal.util.EnumValue"%>
<%@page import="cn.lily.com.db.DBFactory"%>
<%@page import="cn.lily.com.db.container.reader.DataTable"%>
<%@page import="cn.lily.com.lang.VerifyData"%>
<%@page import="cn.lily.web.util.config.WebSetting"%>
<%@ page import="cn.lily.com.configure.util.ESBSetting"%>
<%@ include file="/frames/logbegin.jsp" %>
<%
String appid=WebSetting.getString("single_id");
	String skinName = "";
  String contextPath = "";
  AuthEntity authEntity = (AuthEntity) session.getAttribute(WebContext.LOG_AUTH_CONTEXT);
  if (authEntity != null) {
  	skinName = authEntity.getSkinName();
  	contextPath = authEntity.getContextPath();
  }
  FrameConfig.setContextPath(contextPath);
 
  //获取独立部署路径
  String sql="select app_path,disp_typ from ${schema}.pt_app_info where app_id='"+appid+"'";
  DBManager dbManager1=DBFactory.getActionDB();
  DataTable appTable=dbManager1.executeQueryTable(sql);
  if(appTable.next()) {
	  if("1".equals(appTable.getString("disp_typ"))) {
		  contextPath="http://"+appTable.getString("app_path");
	  }
  }
  //设置应用编号
  authEntity.getOperEntity().setAppID(appid);
  String baseSql="";
  if("9999".equals(authEntity.getOperatorId()) || EnumValue.OPER_TYP_1.equals(authEntity.getOperEntity().getOperType())) {
	baseSql="SELECT * FROM ${schema}.PW_APP_MENU_INFO a WHERE (menu_id IN (SELECT menu_id FROM${schema}. PW_APP_MENU r LEFT JOIN ${schema}.PT_APP_INFO ai ON r.app_id=ai.app_id WHERE r.MENU_ID=a.MENU_ID AND r.APP_ID='"+appid+"' AND ai.APP_STA='"+EnumValue.APP_STA_1+"'))";
  }else{
	baseSql="select * from ${schema}.PW_APP_MENU_INFO where MENU_ID in (select m.menu_id from ${schema}.PW_APP_MENU m LEFT JOIN ${schema}.PT_APP_INFO ai ON m.app_id=ai.app_id where ai.app_sta='"+EnumValue.APP_STA_1+"' and m.menu_id in "+
			"(select c.menu_id from ${schema}.PW_OPER a,${schema}.PW_OPER_ROLE b,${schema}.PW_ROLE_RES c "+
	" where a.oper_key=b.oper_key and b.role_id=c.role_id "+
			"and a.oper_key='"+authEntity.getOperatorId()+"' and c.app_id='"+appid+"') and m.app_id='"+appid+"')";
  }
  DBManager dbManager=DBFactory.getActionDB();
  DataTable menuTable=dbManager.executeQueryTable(baseSql+" and IS_LEAF='0' AND MENU_LEV='1' order by LEVEL_IDX");
%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta http-equiv="X-UA-Compatible" content="IE=Edge">
  <meta charset=utf-8>
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title><%=FrameConfig.getAppName()%></title>
  <link href="<%=contextPath+FrameConfig.getStylePath()%>/strap/bootstrap.min.css" rel="stylesheet" media="screen">
  <link href="<%=FrameConfig.getCSSPath("app.css") %>" rel="stylesheet" />
  <link href="<%=contextPath+FrameConfig.getStylePath()%>/font-awesome/css/font-awesome.min.css" rel="stylesheet">

</head>
<body>
  <div id="main-left">
    <div class="accordion" id="accordion2" >
      <% 
        while(menuTable.next()){
          %>
          <div class="accordion-group menu-pattern">
          <div class="accordion-heading menu-first"><a class="accordion-toggle" data-toggle="collapse" data-target="#menu-<%=menuTable.getString("MENU_ID") %>" data-parent="#accordion2"><%=menuTable.getString("MENU_LAB")%></a></div>
          <%
          DataTable itemTable = DBFactory.getActionDB().executeQueryTable(baseSql+" and IS_LEAF=1 and PAR_MENU_ID='"+menuTable.getString("MENU_ID")+"' order by LEVEL_IDX ");
          if(itemTable.getRecordCount()>0){
            %>
            <div id="menu-<%=menuTable.getString("MENU_ID") %>" class="accordion-body collapse">
                <%
                while(itemTable.next()){
                  String menuSrc="";
                  if(itemTable.getString("MENU_SRC").indexOf("http://")<0){
                	  menuSrc=contextPath+itemTable.getString("MENU_SRC")+"?&sessionID="+session.getId();
                  }else{
                	  menuSrc=itemTable.getString("MENU_SRC");
                  }
                  %>
                  <%--<li><a href="<%=contextPath%>/UI/portal/dict/dictMain.jsp" target="contentFrame"><%=itemTable.getString("MENU_LAB") %></a></li>--%>
                  <div class="accordion-inner menu-second"><a href="<%=menuSrc %>" target="contentFrame" class="menu-second-a"><%=itemTable.getString("MENU_LAB") %></a></div>
                  <%
                }
                %>
            </div>
               <%
          }
          %>
          </div>
        <%
        }
        if("9999".equals(authEntity.getOperatorId()) || EnumValue.OPER_TYP_1.equals(authEntity.getOperEntity().getOperType())){
     	%>
     	<div class="accordion-group menu-pattern">
      		<div class="accordion-heading menu-first"><a class="accordion-toggle" data-toggle="collapse" data-target="#menu-auth" data-parent="#accordion2">权限管理</a></div>
      		<div id="menu-auth" class="accordion-body collapse">
      			<div class="accordion-inner menu-second"><a href="../../../UI/portal/singleapp/role/RoleMain.jsp" target="contentFrame" class="menu-second-a">角色管理</a></div>
      			<div class="accordion-inner menu-second"><a href="../../../UI/portal/singleapp/user/dept.jsp" target="contentFrame" class="menu-second-a">人员管理</a></div>
      		</div>
        </div>
      <%
        }
      dbManager.free();
      %>
      <%@ include file="/frames/logend.jsp" %>
    </div>
  </div>
  <div id="main-right">
    <iframe name="contentFrame" src=""  frameborder="0" height="100%" width="100%"></iframe>
  </div>

  <script src="<%=FrameConfig.getBaseJsUrl() %>/common/jquery-1.9.1.min.js"></script>
  <script src="/<%=ESBSetting.getString("appCode")%>/public/js/skin_bootstrap/bootstrap-3.3.0/bootstrap-3.3.0.js"></script>
  <script src="<%=FrameConfig.getJsUrl("app.js")%>"></script>
  <script type="text/javascript" language="javascript"> 
  $(function(){
  	$(".menu-first a").hover(function(){
		$(this).parent().parent().parent().children().children(".menu-firstv").removeClass("menu-firstv");
		$(this).parent().addClass("menu-firstv");
	});
	$(".menu-first a").click(function(){
		$(this).parent().parent().parent().children().children(".menu-firstv").removeClass("menu-firstv");
		$(this).parent().addClass("menu-firstv");
	});
  	$(".menu-second a").hover(function(){
		$(this).parent().parent().parent().parent().children().children(".menu-firstv").removeClass("menu-firstv");
		$(this).parent().parent().prev().addClass("menu-firstv");
  	});
  	$(".menu-second a").click(function(){
  		$(this).parent().parent().parent().parent().children().children(".menu-firstv").removeClass("menu-firstv");
  		$(this).parent().parent().parent().parent().children().children().children(".menu-second-selected").removeClass("menu-second-selected");
	  	$(this).parent().parent().prev().addClass("menu-firstv");
	  	$(this).parent().addClass("menu-second-selected");
  	});
  })
  </script>
</body>
</html>

